package com.contextor.magiccards.services.test.battle;

import com.contextor.magiccards.dao.utils.ShardHelper;
import com.contextor.magiccards.model.battle.Battle;
import com.contextor.magiccards.model.battle.BattleStatus;
import com.contextor.magiccards.model.cards.MagicSchool;
import com.contextor.magiccards.model.character.Personage;
import com.contextor.magiccards.model.user.User;
import com.contextor.magiccards.services.battle.BattleService;
import com.contextor.magiccards.services.test.AbstractServiceTestCase;
import com.contextor.magiccards.services.user.UserService;
import com.contextor.magiccards.services.user.personage.PersonageService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

/**
 * User: sergey
 * Date: Mar 29, 2011 4:09:26 PM
 */
public class BattleServiceTestCase extends AbstractServiceTestCase {

    @Autowired
    protected BattleService battleService;
    @Autowired
    protected UserService userService;
    @Autowired
    protected PersonageService personageService;

    @Test
    public void testCreationOfNewBattle() throws Exception {
        final int shard = ShardHelper.getDefault();

        final User user = new User();
        user.setId("j234k32hk4h23kj42");
        userService.save(shard, user);

        final User opponent = new User();
        opponent.setId("kj45h6kj5424kg56l");
        userService.save(shard, opponent);

        final Personage character = new Personage(user, "testPlayer", MagicSchool.ORDER);
        personageService.save(shard, character);

        final Battle t = new Battle(user, character, 60);
        battleService.save(shard, t);

        final Battle readyToPlaGame = battleService.findOwnerWithStatus(user, BattleStatus.READY_TO_PLAY);
        Assert.notNull(readyToPlaGame);
    }
}
